package n2255;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static class Tree{
		Tree lchild,rchild;
		char value;
	}
	
	static String prestr;
	static String instr;
	static Tree root;
	
	static void rebuild(Tree root,boolean flag,int start,int end)
	{
		if(start>end)return;
		int r=start;
		int s=prestr.indexOf(instr.charAt(r));
		for(int i=start+1;i<=end;i++)
		{
			int t=prestr.indexOf(instr.charAt(i));
			if(t<s){
				r=i;
				s=t;
			}
		}
		Tree p=new Tree();
		p.value=instr.charAt(r);
		if(root==null)root=p;
		else{
			if(flag)
			{
				root.lchild=p;
			}else{
				root.rchild=p;
			}
		}
		rebuild(p,true,start,r-1);
		rebuild(p,false,r+1,end);
		System.out.print(p.value);
	}
	
	
	static void rebuild2(Tree root,boolean flag,int start,int end,int pstart,int pend)
	{
		if(start>end)return;
		int r=start;
		char ss=prestr.charAt(pstart);
		for(int i=start;i<=end;i++)
		{
			if(instr.charAt(i)==ss){
				r=i;
				break;
			}
		}
		Tree p=new Tree();
		p.value=instr.charAt(r);
		if(root==null)root=p;
		else{
			if(flag)
			{
				root.lchild=p;
			}else{
				root.rchild=p;
			}
		}
		rebuild2(p,true,start,r-1,pstart+1,pstart+r-start);
		rebuild2(p,false,r+1,end,pstart+r-start+1,pstart-start+end);
		System.out.print(p.value);
	}
	
	static void postOrder(Tree p)
	{
		if(p!=null)
		{
			postOrder(p.lchild);
			postOrder(p.rchild);
			System.out.print(p.value);
		}
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		while((line=bf.readLine())!=null)
		{
			StringTokenizer st=new StringTokenizer(line);
			prestr=st.nextToken();
			instr=st.nextToken();
			root=null;
			rebuild(root, true, 0, instr.length()-1);
			System.out.println();
			//postOrder(root);
			//System.out.println();
		}
	}

}
